package com.hand.control;

import com.hand.domain.UserProxy;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;

@RestController
public class ProxyInsert {
    @RequestMapping("/proxyInsert")
    public int proxyInsert() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        UserProxy user = new UserProxy();
        user.setId(9);
        user.setUserName("taoyongfeng");
        user.setName("taotao");
        user.setBirthday(null);
        user.setAge(100);
        user.setUr_id(1);
        user.setUor_id(2);
        int flag = sqlSession.insert("insertToUser",user);
        return flag;
    }
}
